package main

import (
	"QWenVL/actions"
	"QWenVL/config"

	"flag"
	"fmt"
	"log"
	"net/http"

	"github.com/danielgtaylor/huma/v2"
	"github.com/danielgtaylor/huma/v2/adapters/humagin"
	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
)

func Init(path string) {
	config.MustParse(path)

	// models.MustInit()
	// models.MustAutoMigrate()
	// myjwt.InitJwt()
}

func main() {

	var configFile string
	flag.StringVar(&configFile, "c", "./qwenvl.toml", "配置文件路径")
	flag.StringVar(&configFile, "config", "./qwenvl.toml", "配置文件路径")
	flag.Parse()

	Init(configFile)
	// Create a new router & API
	router := gin.New()

	router.Use(cors.New(cors.Config{
		AllowMethods:     []string{"POST", "GET", "PUT", "OPTIONS", "DELETE", "UPDATE", "HEAD"},
		AllowOrigins:     []string{"*"},
		AllowOriginFunc:  func(origin string) bool { return true },
		AllowHeaders:     []string{"*"},
		AllowCredentials: true,
	}))
	api := humagin.New(router, huma.DefaultConfig("Example API", "1.0.0"))

	actions.Register(api)

	addr := fmt.Sprintf("%s:%d", config.GlobalConfig.Service.Addr, config.GlobalConfig.Service.Port)
	log.Fatal(http.ListenAndServe(addr, router))
}
